﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JLL.China.Infrastructure.Services;
using JLL.China.Web.Areas.Portal.Models;
using JLL.China.Web.Libraries;
namespace JLL.China.Web.Areas.Portal.Controllers
{
    public class PagesController : Controller
    {
        //
        // GET: /Portal/Pages/

        public ActionResult Index(int? id)
        {
            if (id!=null)
            {
             
                ViewData["ListBanner"]= PagesService.FindPages((int)id);
                ViewData["ID"] = id.ToString();
              
            }
           
                var model = new BannerModel();
                model.ListPage = PagesService.FindAll();
                model.Statics = BannerService.GetAllBanner("static");
                model.Dynamic = BannerService.GetAllBanner("dynamic");

                return View(model);
           
            
        }
        [HttpPost]
        public ActionResult Index(FormCollection model, IEnumerable<int> banners)
        {
            var pageid = model["listpage"].ToString();
            string _banners = "0";
            if (banners != null)
            {
                foreach (var key in banners)
                {
                    _banners += "," + key.ToString();
                }
                _banners = _banners.Replace("0,", "");
            }
            PagesService.UpdateListBanner(Int32.Parse(pageid),_banners.Trim());
            return RedirectToAction("Index/"+pageid);
        }

    }
}
